package com.wxCompany.robot;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class WxCompanyRobotMessage {

    private String msgtype;
    private Markdown markdown;

    // Constructor
    public WxCompanyRobotMessage(String msgtype, String content) {
        this.msgtype = msgtype;
        this.markdown = new Markdown(content);
    }

    // Getter and Setter
    public String getMsgtype() {
        return msgtype;
    }

    public void setMsgtype(String msgtype) {
        this.msgtype = msgtype;
    }

    public Markdown getMarkdown() {
        return markdown;
    }

    public void setMarkdown(Markdown markdown) {
        this.markdown = markdown;
    }

    // Markdown inner class
    public static class Markdown {
        private String content;

        // Constructor
        public Markdown(String content) {
            this.content = content;
        }

        // Getter and Setter
        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }



    // Helper method to build the content
    public static String buildContent(String text, String path, String req) {
        // 获取当前时间，并格式化为 "yyyy-MM-dd HH:mm:ss"
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        // 构建 content 字符串，注意 text 和 req 需要进行转义
       // String escapedText = text.replace("\"", "\\\"");
     //   String escapedReq = req.replace("\"", "\\\"");

        return String.format(
                "异常：<font color=\"warning\">%s</font>\n请求地址：<font color=\"info\">%s</font>\n请求参数：<font color=\"info\">%s</font>\n时间：%s",
                text, path, req, time);
    }
}
